'use strict';
ymb.controller('record', ['$scope', '$http', 'WeChat', 'WecHat', '$ionicLoading',
function($scope, $http, WeChat, WecHat, $ionicLoading) {
    WeChat.WxData();
    WecHat.inData('资金记录');
    $ionicLoading.show({
        content: 'Loading',
        animation: 'fade-in',
        showBackdrop: true,
        maxWidth: 200,
        showDelay: 0
    });
    $http.post(url + "/loadtrading", {
        currentPage: 1,
        pageCount: 20
    }).success(function(data) {
        $ionicLoading.hide();
        if (data.rows == null) {
            $scope.rows_one = 1;
            return
        }
        if (data.rows != null) {
            $scope.rows_one = 2;
            $scope.interRecord = data.rows;
            return
        }
    })
}]);
ymb.controller('withdrawals', ['$scope', '$http', 'WeChat', 'WecHat', '$PlPup', '$ionicLoading', '$$moeny', '$state', '$ionicViewSwitcher','$ionicPopup',
function($scope, $http, WeChat, WecHat, $PlPup, $ionicLoading, $$moeny, $state, $ionicViewSwitcher,$ionicPopup) {
    WeChat.WxData();
    WecHat.inData('提现');
    $scope.withwals = "";
    $$moeny.$$moEny($scope, $http, $ionicLoading);
    $http.post(url + "/getWithdrawLimit", {}).success(function(data) {
        if (data.code == "00") {
            $scope.data = data.data;
            return
        }
        if (data.code != "00") {
            $PlPup.$model(data.data);
            return
        }
    });
    $scope.hiddenS;
    $scope.bank_id="";
    $http.post(url + "/user/getBankCard", {}).success(function(data) {
        if(data.data==null){
            $scope.hiddenS=false;
            return;
        }
        $scope.cardnumber=data.data.cardnumber;
        $scope.bankname=data.data.bankname;
        $scope.bank_id=data.data.id;
        $scope.hiddenS=true;
    });
    $scope.$on('$ionicView.beforeEnter',
        function() {
            $http.post(url + "/getWithdrawLimit", {}).success(function(data) {
                if (data.code == "00") {
                    $scope.data = data.data;
                    return
                }
                if (data.code != "00") {
                    $PlPup.$model(data.data);
                    return
                }
            });
            $http.post(url + "/user/getBankCard", {}).success(function(data) {
                if(data.data==null){
                    $scope.hiddenS=false;
                    return;
                }
                $scope.cardnumber=data.data.cardnumber;
                $scope.bankname=data.data.bankname;
                $scope.bank_id=data.data.id;
                $scope.hiddenS=true;
            });
        });
    $scope._mask_nu = 1;
    $scope.goBanks=function(){
        $state.go('bank');
    };
    $scope.MoenyInde = function() {
        if ($scope.data.num == 0) {
            $PlPup.$model('今日提现次数已达上限');
            return
        }
        if ($scope._mask_nu == 2) {
            return;
        }
        if ($scope._mask_nu == 1) {
            if ($scope.withwals == "") {
                $PlPup.$model('请输入提现金额');
                return
            }
            if( $scope.hiddenS==false){
                $PlPup.$model('请先添加银行卡');
                return
            }
            $scope._mask_nu = 2;
            $ionicLoading.show({
                content: 'Loading',
                animation: 'fade-in',
                showBackdrop: true,
                maxWidth: 200,
                showDelay: 0
            });
            var withwals = $scope.withwals.toString();
            if (typeof withwals == "string" && typeof withwals != "null") {
                $http.post(url + "/withdraw", {
                    txmoney: Number(withwals),
                    bank_id:$scope.bank_id
                }).success(function(data) {
                    $ionicLoading.hide();
                    $scope._mask_nu = 1;
                    if (data.code == "00") {
                        var alertPopupc_wp = $ionicPopup.alert({
                            title: '提示',
                            template: '提现申请成功，请您注意查收',
                            okText: "知道了"
                        });
                        alertPopupc_wp.then(function (res) {
                            $ionicViewSwitcher.nextDirection('back');
                            window.history.go( - 1);
                        });
                        return
                    }
                    if (data.code != "00") {
                        $PlPup.$model(data.data);
                        return
                    }
                });
            }

            return
        }
    }
}]);
ymb.controller('punching', ['$scope', '$http', 'WeChat', 'WecHat', '$PlPup', '$ionicLoading', '$$moeny', '$state', '$ionicViewSwitcher',
function($scope, $http, WeChat, WecHat, $PlPup, $ionicLoading, $$moeny, $state, $ionicViewSwitcher) {
    WeChat.WxData();
    WecHat.inData('充值');
    $scope.withwals = "";
    $$moeny.$$moEny($scope, $http, $ionicLoading);
    $scope._mash_ok = 1;
    $scope.MoenyInde = function() {
        if ($scope._mash_ok == 1) {
            if ($scope.withwals == "") {
                $PlPup.$model('请输入充值金额');
                return
            }
            $ionicLoading.show({
                content: 'Loading',
                animation: 'fade-in',
                showBackdrop: true,
                maxWidth: 200,
                showDelay: 0
            });
            $scope._mash_ok = 2;
            var withwals = $scope.withwals.toString();
            if (typeof withwals == "string" && typeof withwals != "null") {
                $http.post(url + "/recharge", {
                    czmoney: withwals
                }).success(function(_data) {
                    $ionicLoading.hide();
                    if(_data.code == '99'){
                        window.location.href = _data.data;
                    }else{
                        $scope._mash_ok = 1;
                        wx.config({
                            debug:false,
                            "appId": _data.appId,
                            "timeStamp": _data.timeStamp,
                            "nonceStr": _data.nonceStr,
                            "package": _data.package,
                            "signType": _data.signType,
                            jsApiList: ['checkJsApi', 'getBrandWCPayRequest']
                        });
                        WeixinJSBridge.invoke('getBrandWCPayRequest', {
                                "appId": _data.appId,
                                "timeStamp": _data.timeStamp,
                                "nonceStr": _data.nonceStr,
                                "package": _data.package,
                                "signType": _data.signType,
                                "paySign": _data.paySign
                            },
                            function (res) {
                                if (res.err_msg == "get_brand_wcpay_request:ok") {
                                    var alertPopupc = $ionicPopup.alert({
                                        title: '提示',
                                        template: '充值成功',
                                        okText: '确定'
                                    });
                                    alertPopupc.then(function (res) {
                                        window.history.go(-1)
                                    })
                                } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                                    $PlPup.$model("支付失败");
                                } else {
                                    $PlPup.$model("支付失败");
                                }
                            })
                    }

                })
            }
            return
        }
        if ($scope._mash_ok == 2) {
            return
        }
    }
}]);
ymb.controller('activity', ['$scope', 'WeChat', 'WecHat', '$http', '$$target', '$state', '$ionicViewSwitcher','$ionicPopup',
function($scope, WeChat, WecHat, $http, $$target, $state, $ionicViewSwitcher,$ionicPopup) {
    WeChat.WxData();
    WecHat.inData('最新活动');
    $scope.codeativity = 2;
    $http.get(url + "/index/getNews").success(function(data) {
        if (data.rows.length != 0) {
            $scope.activity_rows = data.rows;
            $scope.codeativity = 1;
            return
        }
        if (data.rows.length == 0) {
            $scope.codeativity = 2;
            return
        }
    })


    $scope.acrivity_up = function($event) {
        var aa = $$target.$$staget($event, "data-href_code").split("#/")[1];
        $http.post(url + '/user/iflogin', {}).success(function(data) {
            if (data.code === '08') {
                $state.go(aa);
            }
            if (data.code !== '08') {
                $ionicPopup.alert({
                    title: '提示',
                    template: '小主，还未登录哦，请先登录再查看详情吧',
                    okText: "知道啦"
                });
                return
            }
        })
        $state.go(aa);
        // window.sessionStorage.setItem("href_journalism", $$target.$$staget($event, "data-href_code"));
        // $state.go('journalism');
        // $ionicViewSwitcher.nextDirection("forward")
    }
}]);
ymb.controller('receipt', ['$scope', '$state', '$ionicViewSwitcher', 'WeChat', 'WecHat', '$http', '$$target', '$PlPup',
function($scope, $state, $ionicViewSwitcher, WeChat, WecHat, $http, $$target, $PlPup) {
    WeChat.WxData();
    WecHat.inData('收货地址');
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    var b = window.sessionStorage.getItem("codein");

    $scope.goMarket = function($event) {
        if (b == 1) {
            window.sessionStorage.setItem("code", $$target.$$staget($event, 'data-intid'));
            window.history.back();
            return
        } else {
            return
        }
    };
    $http.post(url + '/user/getaddresslist', {}).success(function(data) {
        $scope.receiptFor = data.addressList
    });

    $scope.modb = function($event) {
        $state.go('modb', {
            id: $$target.$$staget($event, 'data-id')
        });
        $ionicViewSwitcher.nextDirection("forward")
    };
    $scope.delete = function($event) {
        $http.post(url + '/user/deladdress', {
            id: $$target.$$staget($event, 'data-deleteId'),
            token: $scope.token
        }).success(function(data) {
            if (data.code === "00") {
                location.reload();
                return
            }
            if (data.code !== "00") {
                $scope.token = "";
                $http.get(url + "/user/getToken").success(function(data) {
                    $scope.token = data.data
                });
                $PlPup.$model(data.data);
                return
            }
        })
    }
}]);
function cslot(smd, $scope, $state, $http, $stateParams, $, $PlPup, nk_url) {
    $scope.province = "";
    $scope.city = "";
    $scope.area = "";
    $scope.name = "";
    $scope.phone = "";
    $scope.isdefault = {
        checked: false
    };
    $scope.id = "";
    $scope.Office = "";
    $scope.detailed = "";
    $scope.provinceNumber = 0;
    $scope.provincetext = "";
    $scope.provinceNumbers = 0;
    $scope.provincetexts = "";
    $scope.areastext = "";
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    if (smd === 1) {
        $http.post(url + '/user/findaddress', {
            id: $stateParams.id
        }).success(function(data) {
            $scope.Express = data.data;
            $scope.name = $scope.Express.getuser;
            $scope.id = $scope.Express.id;
            $scope.phone = $scope.Express.phone;
            $.$("province").innerText = $scope.Express.shen;
            $scope.city = $scope.Express.shi;
            $scope.area = $scope.Express.qu;
            $scope.Office = $scope.Express.postal_code;
            $scope.detailed = $scope.Express.address;
            if ($scope.Express.isdefault === 1) {
                $scope.isdefault = {
                    checked: true
                }
            } else {
                $scope.isdefault = {
                    checked: false
                }
            }
        })
    }
    $scope.models = function() {
        $.$('modal').style.display = 'block';
        $http.post(url + '/user/findprovince', {}).success(function(data) {
            $scope.cli = data.data
        });
        $scope.c = function() {
            $scope.provinceNumber = $.$("hello").value;
            $scope.provincetext = $.$("hello").options[$.$("hello").selectedIndex].text;
            $http.post(url + '/user/findcity', {
                code_p: parseInt($scope.provinceNumber)
            }).success(function(data) {
                $scope.clie = data.data
            });
            $scope.areastext = "";
            $scope.provincetexts = ""
        };
        $scope.d = function() {
            $scope.provinceNumbers = $.$("min").value;
            $scope.provincetexts = $.$("min").options[$.$("min").selectedIndex].text;
            $http.post(url + '/user/findarea', {
                code_c: parseInt($scope.provinceNumbers)
            }).success(function(data) {
                $scope.inclice = data.data
            });
            $scope.areastext = ""
        };
        $scope.f = function() {
            $scope.areastext = $.$("areas").options[$.$("areas").selectedIndex].text
        }
    };
    $scope.model_ok = function() {
        if ($scope.provincetext === "") {
            $PlPup.$model('请选择省');
            return
        }
        if ($scope.provincetexts === "") {
            $PlPup.$model('请选择市');
            return
        }
        if ($scope.areastext === "") {
            $PlPup.$model('请选择区');
            return
        }
        $.$("province").innerText = $scope.provincetext;
        $scope.city = $scope.provincetexts;
        $scope.area = $scope.areastext;
        $.$('modal').style.display = 'none'
    };
    $scope.model_no = function() {
        $.$('modal').style.display = 'none'
    };
    $scope.pushNotificationChange = function() {};
    $scope.notnumber = "";
    $scope.Preservation = function() {
        if ($.$("GoodsReceipt").value.length === 0) {
            $PlPup.$model('请输入收货人');
            return
        }
        if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test($.$("phone").value)) {
            $PlPup.$model('请输入正确的电话号码');
            return
        }
        if ($.$("province").length === 0) {
            $PlPup.$model('请选择省');
            return
        }
        if ($scope.city.length === 0) {
            $PlPup.$model('请选择市');
            return
        }
        if ($scope.area.length === 0) {
            $PlPup.$model('请选择区');
            return
        }
        if ($.$("detailed").value.length === 0) {
            $PlPup.$model('请输入正确的详细地址');
            return
        }
        if ($scope.isdefault.checked === true) {
            $scope.notnumber = parseInt(1)
        } else {
            $scope.notnumber = parseInt(0)
        }
        var modifys = "";
        if (smd === 1) {
            modifys = {
                id: parseInt($scope.id),
                getuser: $.$("GoodsReceipt").value,
                phone: $.$("phone").value,
                shen: $.$("province").innerText,
                shi: $scope.city,
                qu: $scope.area,
                postal_code: $.$("Office").value,
                address: $.$("detailed").value,
                isdefault: $scope.notnumber,
                token: $scope.token
            }
        } else {
            modifys = {
                getuser: $.$("GoodsReceipt").value,
                phone: $.$("phone").value,
                shen: $.$("province").innerText,
                shi: $scope.city,
                qu: $scope.area,
                postal_code: $.$("Office").value,
                address: $.$("detailed").value,
                isdefault: $scope.notnumber,
                token: $scope.token
            }
        }
        $http.post(url + nk_url, modifys).success(function(data) {
            if (data.code === "33") {
                window.history.back();
                return
            }
            if (data.code !== "33") {
                $scope.token = "";
                $http.get(url + "/user/getToken").success(function(data) {
                    $scope.token = data.data
                });
                $PlPup.$model(data.data);
                return
            }
        })
    }
};
ymb.controller('build', ['$scope', '$state', '$http', '$PlPup', 'WeChat', 'WecHat', '$', '$class_mp', '$stateParams',
function($scope, $state, $http, $PlPup, WeChat, WecHat, $, $stateParams) {
    WeChat.WxData();
    WecHat.inData('新建地址');
    cslot(2, $scope, $state, $http, $stateParams, $, $PlPup, '/user/addaddress')
}]);
ymb.controller('modb', ['$scope', '$state', '$http', 'WeChat', 'WecHat', '$', '$class_mp', '$stateParams', '$PlPup',
function($scope, $state, $http, WeChat, WecHat, $, $class_mp, $stateParams, $PlPup) {
    WeChat.WxData();
    WecHat.inData('修改地址');
    cslot(1, $scope, $state, $http, $stateParams, $, $PlPup, '/user/updateaddress')
}]);
ymb.factory('$$Pasture',
function($http, $ionicLoading) {
    var $Pasture = {};
    $Pasture.$Pasture_up = function($scope, type) {
        $http.post(url + "/saleproduct/saleproductall", {
            pro_type: type,
            currentPage: 1,
            pageCount: 1000
        }).success(function(data) {
            $ionicLoading.hide();
            try {
                $scope.int_salep = 1;
                typeof(data.data) == "object" && data.data.length != 0 ? $scope.salep = data.data: $scope.int_salep = 2
            } catch(data) {
                $scope.int_salep = 2
            }
        })
    };
    return $Pasture
});
ymb.controller('detailedmp', ['$scope', '$state', '$ionicViewSwitcher', '$http', '$$Pasture', '$$target', '$ionicLoading',
function($scope, $state, $ionicViewSwitcher, $http, $$Pasture, $$target, $ionicLoading) {
    $scope.e = 1;
    $scope.b = "";
    $scope.w = "";
    $scope.Order_active = 'Order_active';
    $ionicLoading.show({
        content: 'Loading',
        animation: 'fade-in',
        showBackdrop: true,
        maxWidth: 200,
        showDelay: 0
    });
    $$Pasture.$Pasture_up($scope, 1);
    $scope.View_switch = function(l, i, o) {
        $scope.e = l;
        $scope.b = i;
        $scope.w = o;
        if (l === 1) {
            $$Pasture.$Pasture_up($scope, 1);
            return
        }
        if (i === 1) {
            $$Pasture.$Pasture_up($scope, 2);
            return
        }
        if (o === 1) {
            $$Pasture.$Pasture_up($scope, 3);
            return
        }
    };
    $scope.refresh = function() {
        $scope.e == 1 ? $$Pasture.$Pasture_up($scope, 1) : $scope.b == 1 ? $$Pasture.$Pasture_up($scope, 2) : $$Pasture.$Pasture_up($scope, 3);
        $scope.$broadcast("scroll.refreshComplete")
    };
    $scope.commodity = function($event) {
        $state.go('pasture', {
            oid: $$target.$$staget($event, 'data-idint')
        });
        $ionicViewSwitcher.nextDirection("forward")
    }
}]);
ymb.controller('pasture', ['$scope', '$http', '$state', '$ionicViewSwitcher', 'WeChat', 'WecHat', '$stateParams', '$', '$PlPup',
function($scope, $http, $state, $ionicViewSwitcher, WeChat, WecHat, $stateParams, $, $PlPup) {
    WeChat.WxData();
    WecHat.inData('友牧商场');
    $scope.sp_name = "";
    $scope.sp_id = "";
    $scope.sp_jg = "";
    $scope.sp_img = "";
    $scope.number_up = 1;
    $http.post(url + "/saleproduct/selectsaleproductone", {
        id: $stateParams.oid
    }).success(function(data) {
        $scope.shopping_cart_num_lp = data.shopping_cart_num;
        $scope.not = data.wbSaleProduct;
        $scope.sp_name = data.wbSaleProduct.name;
        $scope.sp_id = data.wbSaleProduct.id;
        $scope.sp_jg = data.wbSaleProduct.price;
        $scope.sp_img = data.wbSaleProduct.photo_url;
        $scope.$on('$ionicView.afterEnter',
        function() {
            $scope.detail_photo = data.wbSaleProduct.detail_photo
        });
        $scope.plus = function() {
            $scope.number_up++
        };
        $scope.reduce = function() {
            if ($scope.number_up === 1) {
                $scope.number_up = 1;
                return
            }
            $scope.number_up--
        };
        $scope.purchase = function() {
            $http.post(url + '/user/iflogin', {}).success(function(data) {
                if (data.code === '08') {
                    window.sessionStorage.setItem("number_up", $scope.number_up);
                    window.sessionStorage.setItem("oid_up", $stateParams.oid);
                    window.sessionStorage.setItem("name_up", $scope.not.name);
                    window.sessionStorage.setItem("price_up", $scope.not.price);
                    window.sessionStorage.setItem("photo_url_up", $scope.not.photo_url);
                    $state.go('okorder');
                    $ionicViewSwitcher.nextDirection("forward");
                    return true
                }
                if (data.code !== '08') {
                    $state.go("sign");
                    $ionicViewSwitcher.nextDirection("forward");
                    return true
                }
            })
        };
        $scope.shoppingCart = function() {
            $http.post(url + '/user/iflogin', {}).success(function(data) {
                if (data.code === '08') {
                    $http.post(url + "/add2Cart", {
                        productid: $stateParams.oid,
                        amount: $scope.number_up
                    }).success(function(data) {
                        if (data.code === "00") {
                            $http.post(url + "/saleproduct/selectsaleproductone", {
                                id: $stateParams.oid
                            }).success(function(data) {
                                $scope.shopping_cart_num_lp = data.shopping_cart_num
                            });
                            $PlPup.$model("商品添加成功，请在购物车结算");
                            return
                        }
                        if (data.code !== "00") {
                            $PlPup.$model(data.data);
                            return
                        }
                    });
                    return true
                }
                if (data.code !== '08') {
                    $state.go("sign");
                    $ionicViewSwitcher.nextDirection("forward");
                    return true
                }
            })
        }
    });
    $scope.sp_ewm = function() {
        $http.get(url + "/user/getposter", {
            params: {
                "pro_Id": $scope.sp_id,
                "pro_price": $scope.sp_jg,
                "pro_name": $scope.sp_name,
                "pro_poto_url": $scope.sp_img
            }
        }).success(function(data) {
            $state.go("seal", {
                img: data.data
            })
        })
    };
    $scope.elastic = function() {
        $.$("zg_mp_models").style.display = "block"
    };
    $scope.Close_elastic = function() {
        $.$("zg_mp_models").style.display = "none"
    };
    window.sessionStorage.removeItem("code");
    window.sessionStorage.removeItem("codein");
    window.sessionStorage.removeItem("spgo");
    window.sessionStorage.removeItem("play_sessin");
    window.sessionStorage.removeItem("sp_id");
    window.sessionStorage.removeItem("dataId");
    window.sessionStorage.removeItem("order_type")
}]);
ymb.controller('seal', ['$scope', 'WeChat', 'WecHat', '$stateParams',
function($scope, WeChat, WecHat, $stateParams) {
    WeChat.WxData();
    WecHat.inData('海报中心');
    $scope.int_gb_img = url + $stateParams.img
}]);
ymb.controller('okorder', ['$scope', '$http', '$state', '$ionicViewSwitcher', '$stateParams', 'WeChat', 'WecHat', '$$moeny', '$PlPup', '$ionicPopup', '$okgo', '$ionicLoading',
function($scope, $http, $state, $ionicViewSwitcher, $stateParams, WeChat, WecHat, $$moeny, $PlPup, $ionicPopup, $okgo, $ionicLoading) {
    WeChat.WxData();
    WecHat.inData('订单确认');
    $scope.order_num = window.sessionStorage.getItem("number_up");
    $scope.order_oig = window.sessionStorage.getItem("oid_up");
    $scope.name = window.sessionStorage.getItem("name_up");
    $scope.price = window.sessionStorage.getItem("price_up");
    $scope.inimg = window.sessionStorage.getItem("photo_url_up");
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $scope.savenum = 0;
    $scope.idnumver = '';
    $scope.transmission = "overpay";
    $scope.weChat_yd = "cmoder11.png";
    $scope.sinaPay_yd = "cmoder11.png";
    $scope.overpay = "cmoder10.png";
    $scope.transmiss_pay = function(x) {
        if (x === 1) {
            $scope.transmission = "weChat";
            $scope.weChat_yd = "cmoder10.png";
            $scope.sinaPay_yd = "cmoder11.png";
            $scope.overpay = "cmoder11.png"
        } else if (x === 2) {
            $scope.transmission = "sinaPay";
            $scope.weChat_yd = "cmoder11.png";
            $scope.sinaPay_yd = "cmoder10.png";
            $scope.overpay = "cmoder11.png"
        } else if (x === 3) {
            $scope.transmission = "overpay";
            $scope.weChat_yd = "cmoder11.png";
            $scope.sinaPay_yd = "cmoder11.png";
            $scope.overpay = "cmoder10.png"
        }
    };
    $scope.to_lick = window.sessionStorage.getItem("play_sessin");
    if ($scope.to_lick == 1) {
        $scope.display_pay = 2
    } else if ($scope.to_lick != 1) {
        $scope.display_pay = 1
    }
    $scope.sp_id = "";
    $scope.dataId = "";
    $scope.toht = 1;
    var spgo = window.sessionStorage.getItem("spgo");
    $scope.spseiiw = 1;
    $scope.push = 0;
    if (spgo != null) {
        $http.post(url + "/saleproduct/selectcouponmeetnum", {
            shopCart: spgo
        }).success(function(data) {
            $scope.total_price = data.total_price;
            $scope.meetnum = data.wbCouponNum;
            $scope.spnit = $scope.total_price - $scope.savenum
        });
        $http.post(url + "/user/selectshopcart", {
            shopCart: spgo
        }).success(function(data) {
            $scope.wbSaleProductList = data.data;
            for (var i = 0; i < $scope.wbSaleProductList.length; i++) {
                $scope.push += $scope.wbSaleProductList[i].shopingCartNum
            }
        });
        $scope.spseiiw = 2;
        $scope.ok_Discount = function() {
            $state.go('save', {
                id: spgo
            });
            $ionicViewSwitcher.nextDirection("forward")
        };
        $scope.feweclick = function() {
            if ($scope.toht == 1) {
                if ($scope.incliceFok === 2) {
                    $PlPup.$model('请选择收货地址');
                    return
                }
                $scope.toht = 2;
                var dataint = {
                    vid: $scope.saveId,
                    shopCart: spgo,
                    address_id: $scope.in_ok_id,
                    order_type: 1,
                    post_remark: 0,
                    token: $scope.token,
                    user_key: window.sessionStorage.getItem("super_key_up")
                };
                $http.post(url + "/user/submitallorder", dataint).success(function(data) {
                    $scope.toht = 1;
                    if (data.code === "00") {
                        window.sessionStorage.setItem("play_sessin", 1);
                        $scope.display_pay = 2;
                        $scope.sp_id = data.dataid;
                        $scope.dataId = data.dataid;
                        window.sessionStorage.setItem("dataId", data.dataid);
                        window.sessionStorage.setItem("sp_id", data.dataid);
                        window.sessionStorage.setItem("order_type", data.orderType);
                        return
                    }
                    if (data.code !== "00") {
                        $scope.token = "";
                        $http.get(url + "/user/getToken").success(function(data) {
                            $scope.token = data.data
                        });
                        $PlPup.$model(data.data)
                    }
                });
                return
            }
            if ($scope.toht == 2) {
                return
            }
        }
    } else {
        $http.post(url + "/saleproduct/selectcouponmeetnum", {
            id: $scope.order_oig,
            pro_count: $scope.order_num
        }).success(function(data) {
            $scope.meetnum = data.wbCouponNum
        });
        $scope.spseiiw = 3;
        $scope.ok_Discount = function() {
            $state.go('save', {
                id: $scope.order_oig,
                num: $scope.order_num
            });
            $ionicViewSwitcher.nextDirection("forward")
        };
        $scope.feweclick = function() {
            if ($scope.toht == 1) {
                if ($scope.incliceFok === 2) {
                    $PlPup.$model('请选择收货地址');
                    return
                }
                $scope.toht = 2;
                var dataint = {
                    vid: $scope.saveId,
                    product_id: $scope.order_oig,
                    pro_count: $scope.order_num,
                    address_id: $scope.in_ok_id,
                    order_type: 1,
                    post_remark: 0,
                    token: $scope.token,
                    user_key: window.sessionStorage.getItem("super_key_up")
                };
                $http.post(url + "/user/submitorder", dataint).success(function(data) {
                    $scope.toht = 1;
                    if (data.code === "00") {
                        window.sessionStorage.setItem("play_sessin", 1);
                        $scope.display_pay = 2;
                        $scope.sp_id = data.dataid;
                        $scope.dataId = data.dataid;
                        window.sessionStorage.setItem("dataId", data.dataid);
                        window.sessionStorage.setItem("sp_id", data.dataid);
                        window.sessionStorage.setItem("order_type", data.orderType);
                        return
                    }
                    if (data.code !== "00") {
                        $scope.token = "";
                        $http.get(url + "/user/getToken").success(function(data) {
                            $scope.token = data.data
                        });
                        $PlPup.$model(data.data)
                    }
                });
                return
            }
            if ($scope.toht == 2) {
                return
            }
        }
    }
    $scope.go_pay_wp = function() {
        if ($scope.toht == 1) {
            $scope.toht = 2;
            if ($scope.transmission == "sinaPay") {
                $http.post(url + '/user/ifidentification', {}).success(function(data) {
                    if (data.code === '00') {
                        $http.post(url + "/user/selectsinamoneycheck", {}).success(function(data) {
                            if (data.isSet == "N") {
                                $scope.toht = 1;
                                window.sessionStorage.setItem("sinAPwdHref", data.redirectUrl);
                                $state.go('sinapwd');
                                $ionicViewSwitcher.nextDirection("forward");
                                return
                            }
                            if (data.isSet == "Y") {
                                $http.post(url + "/user/orderpay", {
                                    banktype: $scope.transmission,
                                    orderId: window.sessionStorage.getItem("sp_id")
                                }).success(function(data) {
                                    $scope.toht = 1;
                                    if (data.code == "00") {
                                        window.sessionStorage.setItem("playiframe", data.redirect_url);
                                        $state.go('playiframe');
                                        $ionicViewSwitcher.nextDirection("forward");
                                        return
                                    }
                                    if (data.code !== "00") {
                                        $ionicPopup.alert({
                                            title: '提示',
                                            template: '支付失败',
                                            okText: '确定'
                                        });
                                        return
                                    }
                                });
                                return
                            }
                        });
                        return
                    }
                    if (data.code != '00') {
                        $scope.toht = 1;
                        $okgo.$$go('real');
                        return
                    }
                });
                return
            }
            if ($scope.transmission == "weChat") {
                $http.post(url + "/savePayOrder_wx", {
                    dataId: window.sessionStorage.getItem("dataId"),
                    orderType: window.sessionStorage.getItem("order_type"),
                    payType: $scope.transmission
                }).success(function(data) {
                    $http.post(url + "/getWxPayid", {
                        orderid: data.orderid
                    }).success(function(data) {
                        $scope.toht = 1;
                        WeixinJSBridge.invoke('getBrandWCPayRequest', {
                            "appId": data.appId,
                            "timeStamp": data.timeStamp,
                            "nonceStr": data.nonceStr,
                            "package": data.package,
                            "signType": data.signType,
                            "paySign": data.paySign
                        },
                        function(res) {
                            if (res.err_msg == "get_brand_wcpay_request:ok") {
                                var alertPopupc = $ionicPopup.alert({
                                    title: '提示',
                                    template: '支付成功',
                                    okText: '确定'
                                });
                                alertPopupc.then(function(res) {
                                    if (spgo != null) {
                                        window.history.go( - 1)
                                    } else {
                                        window.history.go( - 2)
                                    }
                                })
                            } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                                return
                            } else {
                                return
                            }
                        })
                    })
                });
                return
            }
            if ($scope.transmission == "overpay") {
                var confirmPopup = $ionicPopup.confirm({
                    title: '提示',
                    template: '是否确定支付',
                    cancelText: '否',
                    okText: '是'
                });
                confirmPopup.then(function(res) {
                    if (res) {
                        $http.post(url + "/user/orderpay", {
                            banktype: $scope.transmission,
                            orderId: window.sessionStorage.getItem("sp_id")
                        }).success(function(data) {
                            $scope.toht = 1;
                            if (data.code == "00") {
                                var alertPopupc = $ionicPopup.alert({
                                    title: '提示',
                                    template: '支付成功',
                                    okText: '确定'
                                });
                                alertPopupc.then(function(res) {
                                    if (spgo != null) {
                                        window.history.go( - 1)
                                    } else {
                                        window.history.go( - 2)
                                    }
                                });
                                return
                            }
                            if (data.code !== "00") {
                                $ionicPopup.alert({
                                    title: '提示',
                                    template: data.data,
                                    okText: '确定'
                                });
                                return
                            }
                        });
                        return
                    } else {
                        $scope.toht = 1
                    }
                });
                return
            }
            return
        }
        if ($scope.toht == 2) {
            return
        }
    };
    var inid = window.sessionStorage.getItem("inids");
    if (inid === null) {
        $scope.saveId = null
    } else {
        var int = String(inid).split(",");
        $scope.savenum = int[1];
        $scope.saveId = int[0]
    }
    $scope.incliceFok = 1;
    $scope.goReceipt = function() {
        window.sessionStorage.setItem("codein", 1);
        $state.go("receipt")
    };
    $scope.in_ok_id = "";
    var b = window.sessionStorage.getItem("code");
    if (b === null) {
        $http.post(url + "/user/finddefaultaddress", {}).success(function(data) {
            if (data.data == "null") {
                $scope.incliceFok = 2;
                return
            } else {
                $scope.datato = data.data;
                $scope.in_ok_id = $scope.datato.id;
                $scope.incliceFok = 1;
                return
            }
        })
    } else {
        $http.post(url + "/user/findaddress", {
            id: b
        }).success(function(data) {
            $scope.in_ok_id = data.data.id;
            $scope.datato = data.data
        })
    }
    $scope.conumber = $scope.price * $scope.order_num;
    $scope.nit = $scope.conumber - $scope.savenum;
    $$moeny.$$moEny($scope, $http, $ionicLoading);
    window.sessionStorage.removeItem("inids")
}]);
ymb.factory('$Coupon',
function() {
    var $$$Coupon = {};
    $$$Coupon.$$Coupon = function($scope, $http, urls, $stateParams) {
        $scope.insave = 1;
        var spgo = window.sessionStorage.getItem("spgo");
        if (spgo != null) {
            $http.post(url + urls, {
                shopCart: $stateParams.id
            }).success(function(data) {
                if (data.wbCouponList == "") {
                    $scope.insave = 2
                }
                if (data.wbCouponList != "") {
                    $scope.available = data.wbCouponList;
                    $scope.insave = 1;
                    return
                }
            })
        } else {
            $http.post(url + urls, {
                id: $stateParams.id,
                pro_count: $stateParams.num
            }).success(function(data) {
                if (data.wbCouponList == "") {
                    $scope.insave = 2
                }
                if (data.wbCouponList != "") {
                    $scope.available = data.wbCouponList;
                    $scope.insave = 1;
                    return
                }
            })
        }
    };
    return $$$Coupon
});
ymb.controller('save', ['$scope', '$http', 'WeChat', 'WecHat', '$stateParams', '$Coupon', '$$target',
function($scope, $http, WeChat, WecHat, $stateParams, $Coupon, $$target) {
    WeChat.WxData();
    WecHat.inData('优惠券');
    $scope.e = 1;
    $scope.View_switch = function(l, i) {
        $scope.e = l;
        $scope.b = i;
        if (l === 1) {
            $Coupon.$$Coupon($scope, $http, "/saleproduct/selectcouponmeet", $stateParams);
            return
        }
        if (i === 1) {
            $Coupon.$$Coupon($scope, $http, "/saleproduct/selectcoupondissatisfy", $stateParams);
            return
        }
    };
    $Coupon.$$Coupon($scope, $http, "/saleproduct/selectcouponmeet", $stateParams);
    $scope.lifeclick = function($event) {
        var inid = $$target.$$staget($event, "data-inid");
        var number = $$target.$$staget($event, "data-number");
        var inids = new Array(inid, number);
        window.sessionStorage.setItem("inids", inids);
        window.history.back()
    }
}]);
